package com.sailfish.springbootdemo.service.db1;

import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.sailfish.springbootdemo.configs.UserHeaderHolder;
import com.sailfish.springbootdemo.dao.db1.RoadmapBigTypeDao;
import com.sailfish.springbootdemo.dao.db1.RoadmapH3cDao;
import com.sailfish.springbootdemo.dao.db1.RoadmapParamDao;
import com.sailfish.springbootdemo.dao.db1.RoadmapSmallTypeDao;
import com.sailfish.springbootdemo.pojo.Result;
import com.sailfish.springbootdemo.pojo.db1.*;
import com.sailfish.springbootdemo.pojo.db4.Operate;
import com.sailfish.springbootdemo.service.db4.OperateService;
import com.sailfish.springbootdemo.utils.CommonUtils;
import com.sailfish.springbootdemo.utils.FileConverterUtils;
import com.sailfish.springbootdemo.utils.ResultUtil;
import org.apache.poi.ss.usermodel.*;
import org.apache.poi.ss.util.CellRangeAddress;
import org.apache.poi.xssf.usermodel.XSSFWorkbook;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.jdbc.datasource.DataSourceTransactionManager;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.transaction.interceptor.TransactionAspectSupport;
import org.springframework.web.multipart.MultipartFile;

import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.InputStream;
import java.util.*;

@Service
public class RoadmapH3cServiceImpl implements RoadmapH3cService {

    @Autowired
    private RoadmapParamDao roadmapParamDao;

    @Autowired
    private RoadmapH3cDao roadmapH3cDao;

    @Qualifier("MysqlTransactionManager1")
    @Autowired
    private DataSourceTransactionManager transactionManager1;

    @Value("${personal.config.file.file-save-url}")
    private String fileSaveUrl;

    @Autowired
    private OperateService operateService;

    @Autowired
    private RoadmapBigTypeDao roadmapBigTypeDao;

    @Autowired
    private RoadmapSmallTypeDao roadmapSmallTypeDao;

    private String operateSmallType = "Roadmap H3C";

    @Transactional(transactionManager = "MysqlTransactionManager1")
    @Override
    public Result updateRoadmapParamByBigType(String data) {
        try {
            JSONObject jsonObject = JSONObject.parseObject(data);
            String roadmapBigTypeId = jsonObject.getString("roadmapBigTypeId");
            String year = jsonObject.getString("year");
            String versionY = jsonObject.getString("versionY");
            String versionN = jsonObject.getString("versionN");
            JSONArray roadmapParamArr = jsonObject.getJSONArray("roadmapParamArr");
            if (roadmapBigTypeId == null || "".equals(roadmapBigTypeId)) {
                return ResultUtil.error(500, "缺少参数roadmapBigTypeId", "Miss Param roadmapBigTypeId", null);
            }

            if (year == null || "".equals(year)) {
                return ResultUtil.error(500, "缺少参数year", "Miss Param year", null);
            }
            if (versionY == null || "".equals(versionY)) {
                return ResultUtil.error(500, "缺少参数versionY", "Miss Param versionY", null);
            }
            if (versionN == null || "".equals(versionN)) {
                return ResultUtil.error(500, "缺少参数versionN", "Miss Param versionN", null);
            }

            String userId = UserHeaderHolder.getUserId();

            // 删除原先的
            List<RoadmapParam> allRoadmapParam = roadmapParamDao.getAllRoadmapParam(null, Integer.parseInt(roadmapBigTypeId), null);
            for (RoadmapParam roadmapParam : allRoadmapParam) {
                roadmapH3cDao.deleteRoadmapH3cByKey(roadmapParam.getRoadmapParamKey(), Integer.parseInt(year), Integer.parseInt(versionY), versionN);
            }

            // 操作日志
            operateService.addOperate(new Operate(1, Integer.parseInt(userId), operateSmallType, 2, 1, new Date(), JSONObject.toJSONString(allRoadmapParam), null));

            List<RoadmapH3c> list = new ArrayList<>();
            // 再新增
            for (Object o : roadmapParamArr) {
                JSONObject roadmapParamObj = (JSONObject) o;
                RoadmapH3c addRoadmapH3c = new RoadmapH3c();
                addRoadmapH3c.setRoadmapH3cParamKey(roadmapParamObj.getString("roadmapH3cParamKey"));
                addRoadmapH3c.setRoadmapH3cParamValue1(roadmapParamObj.getString("roadmapH3cParamValue1"));
                addRoadmapH3c.setRoadmapH3cParamValue2(roadmapParamObj.getString("roadmapH3cParamValue2"));
                addRoadmapH3c.setRoadmapH3cParamValue3(roadmapParamObj.getString("roadmapH3cParamValue3"));
                addRoadmapH3c.setSort(Integer.parseInt(roadmapParamObj.getString("sort")));
                addRoadmapH3c.setStatus(Integer.parseInt(roadmapParamObj.getString("status")));
                addRoadmapH3c.setCreateTime(new Date());
                addRoadmapH3c.setYear(Integer.parseInt(year));
                roadmapH3cDao.addRoadmapH3c(addRoadmapH3c);
                list.add(addRoadmapH3c);
            }

            // 操作日志
            operateService.addOperate(new Operate(1, Integer.parseInt(userId), operateSmallType, 1, 1, new Date(), null, JSONObject.toJSONString(list)));

            return ResultUtil.success(null);
        } catch (Exception e) {
            TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
            e.printStackTrace();
            return ResultUtil.error(500, e.getMessage(), e.getMessage(), null);
        }
    }

    @Transactional(transactionManager = "MysqlTransactionManager1")
    @Override
    public Result updateRoadmapParamByBigTypeNew(String data) {
        try {
            JSONObject jsonObject = JSONObject.parseObject(data);
            String roadmapBigTypeId = jsonObject.getString("roadmapBigTypeId");
            String year = jsonObject.getString("year");
            String versionY = jsonObject.getString("versionY");
            String versionN = jsonObject.getString("versionN");
            JSONArray roadmapParamArr1 = jsonObject.getJSONArray("roadmapParamArr1");
            JSONArray roadmapParamArr2 = jsonObject.getJSONArray("roadmapParamArr2");
            JSONArray roadmapParamArr3 = jsonObject.getJSONArray("roadmapParamArr3");
            if (roadmapBigTypeId == null || "".equals(roadmapBigTypeId)) {
                return ResultUtil.error(500, "缺少参数roadmapBigTypeId", "Miss Param roadmapBigTypeId", null);
            }

            if (year == null || "".equals(year)) {
                return ResultUtil.error(500, "缺少参数year", "Miss Param year", null);
            }
            if (versionY == null || "".equals(versionY)) {
                return ResultUtil.error(500, "缺少参数versionY", "Miss Param versionY", null);
            }

            if (versionN == null || "".equals(versionN)) {
                return ResultUtil.error(500, "缺少参数versionN", "Miss Param versionN", null);
            }


            String userId = UserHeaderHolder.getUserId();
            List<RoadmapH3c> oldRoadmapH3cList = new ArrayList<>();

            // 删除原先的
            List<RoadmapParam> allRoadmapParam = roadmapParamDao.getAllRoadmapParam(null, Integer.parseInt(roadmapBigTypeId), null);
            for (RoadmapParam roadmapParam : allRoadmapParam) {
                roadmapH3cDao.deleteRoadmapH3cByKey(roadmapParam.getRoadmapParamKey(), Integer.parseInt(year), Integer.parseInt(versionY), versionN);
                roadmapH3cDao.deleteRoadmapH3cByKey(roadmapParam.getRoadmapParamKey(), Integer.parseInt(year) + 1, Integer.parseInt(versionY), versionN);
                roadmapH3cDao.deleteRoadmapH3cByKey(roadmapParam.getRoadmapParamKey(), Integer.parseInt(year) + 2, Integer.parseInt(versionY), versionN);

                RoadmapH3c roadmapH3c1 = new RoadmapH3c();
                roadmapH3c1.setRoadmapH3cParamKey(roadmapParam.getRoadmapParamKey());
                roadmapH3c1.setYear(Integer.parseInt(year));

                RoadmapH3c roadmapH3c2 = new RoadmapH3c();
                roadmapH3c2.setRoadmapH3cParamKey(roadmapParam.getRoadmapParamKey());
                roadmapH3c2.setYear(Integer.parseInt(year) + 1);

                RoadmapH3c roadmapH3c3 = new RoadmapH3c();
                roadmapH3c3.setRoadmapH3cParamKey(roadmapParam.getRoadmapParamKey());
                roadmapH3c3.setYear(Integer.parseInt(year) + 2);

                oldRoadmapH3cList.add(roadmapH3c1);
                oldRoadmapH3cList.add(roadmapH3c2);
                oldRoadmapH3cList.add(roadmapH3c3);
            }

            // 操作日志
            operateService.addOperate(new Operate(1, Integer.parseInt(userId), operateSmallType, 2, 1, new Date(), JSONObject.toJSONString(oldRoadmapH3cList), null));

            List<RoadmapH3c> list = new ArrayList<>();
            // 再新增
            for (Object o : roadmapParamArr1) {
                JSONObject roadmapParamObj = (JSONObject) o;
                RoadmapH3c addRoadmapH3c = new RoadmapH3c();
                addRoadmapH3c.setRoadmapH3cParamKey(roadmapParamObj.getString("roadmapH3cParamKey"));
                addRoadmapH3c.setRoadmapH3cParamValue1(roadmapParamObj.getString("roadmapH3cParamValue1"));
                addRoadmapH3c.setRoadmapH3cParamValue2(roadmapParamObj.getString("roadmapH3cParamValue2"));
                addRoadmapH3c.setRoadmapH3cParamValue3(roadmapParamObj.getString("roadmapH3cParamValue3"));
                addRoadmapH3c.setSort(Integer.parseInt(roadmapParamObj.getString("sort")));
                addRoadmapH3c.setStatus(Integer.parseInt(roadmapParamObj.getString("status")));
                addRoadmapH3c.setCreateTime(new Date());
                addRoadmapH3c.setYear(Integer.parseInt(year));
                addRoadmapH3c.setVersionY(Integer.parseInt(versionY));
                addRoadmapH3c.setVersionN(versionN);
                roadmapH3cDao.addRoadmapH3c(addRoadmapH3c);
                list.add(addRoadmapH3c);
            }
            for (Object o : roadmapParamArr2) {
                JSONObject roadmapParamObj = (JSONObject) o;
                RoadmapH3c addRoadmapH3c = new RoadmapH3c();
                addRoadmapH3c.setRoadmapH3cParamKey(roadmapParamObj.getString("roadmapH3cParamKey"));
                addRoadmapH3c.setRoadmapH3cParamValue1(roadmapParamObj.getString("roadmapH3cParamValue1"));
                addRoadmapH3c.setRoadmapH3cParamValue2(roadmapParamObj.getString("roadmapH3cParamValue2"));
                addRoadmapH3c.setRoadmapH3cParamValue3(roadmapParamObj.getString("roadmapH3cParamValue3"));
                addRoadmapH3c.setSort(Integer.parseInt(roadmapParamObj.getString("sort")));
                addRoadmapH3c.setStatus(Integer.parseInt(roadmapParamObj.getString("status")));
                addRoadmapH3c.setCreateTime(new Date());
                addRoadmapH3c.setYear(Integer.parseInt(year) + 1);
                addRoadmapH3c.setVersionY(Integer.parseInt(versionY));
                addRoadmapH3c.setVersionN(versionN);
                roadmapH3cDao.addRoadmapH3c(addRoadmapH3c);
                list.add(addRoadmapH3c);
            }
            for (Object o : roadmapParamArr3) {
                JSONObject roadmapParamObj = (JSONObject) o;
                RoadmapH3c addRoadmapH3c = new RoadmapH3c();
                addRoadmapH3c.setRoadmapH3cParamKey(roadmapParamObj.getString("roadmapH3cParamKey"));
                addRoadmapH3c.setRoadmapH3cParamValue1(roadmapParamObj.getString("roadmapH3cParamValue1"));
                addRoadmapH3c.setRoadmapH3cParamValue2(roadmapParamObj.getString("roadmapH3cParamValue2"));
                addRoadmapH3c.setRoadmapH3cParamValue3(roadmapParamObj.getString("roadmapH3cParamValue3"));
                addRoadmapH3c.setSort(Integer.parseInt(roadmapParamObj.getString("sort")));
                addRoadmapH3c.setStatus(Integer.parseInt(roadmapParamObj.getString("status")));
                addRoadmapH3c.setCreateTime(new Date());
                addRoadmapH3c.setYear(Integer.parseInt(year) + 2);
                addRoadmapH3c.setVersionY(Integer.parseInt(versionY));
                addRoadmapH3c.setVersionN(versionN);
                roadmapH3cDao.addRoadmapH3c(addRoadmapH3c);
                list.add(addRoadmapH3c);
            }

            // 操作日志
            operateService.addOperate(new Operate(1, Integer.parseInt(userId), operateSmallType, 1, 1, new Date(), null, JSONObject.toJSONString(list)));

            return ResultUtil.success(null);
        } catch (Exception e) {
            TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
            e.printStackTrace();
            return ResultUtil.error(500, e.getMessage(), e.getMessage(), null);
        }
    }

    @Override
    public Result getThreeYearsHecParamValue(Integer versionY, String versionN) {
        try {
            if (versionY == null || "".equals(versionY.toString())) {
                return ResultUtil.error(500, "缺少参数versionY", "Miss Param versionY", null);
            }
            if (versionN == null || "".equals(versionN)) {
                return ResultUtil.error(500, "缺少参数versionN", "Miss Param versionN", null);
            }
            // 今年
            Calendar cal = Calendar.getInstance();
            Integer year = cal.get(Calendar.YEAR);
            //明年
            Integer yearAdd1 = year + 1;
            //后年
            Integer yearAdd2 = year + 2;

            List<RoadmapH3c> allRoadmapH3c = roadmapH3cDao.getAllRoadmapH3c(year, versionY, versionN);
            for (RoadmapH3c roadmapH3c : allRoadmapH3c) {
                roadmapH3c.setCurrentYearValue1(roadmapH3c.getRoadmapH3cParamValue1());
                roadmapH3c.setCurrentYearValue2(roadmapH3c.getRoadmapH3cParamValue2());
                roadmapH3c.setCurrentYearValue3(roadmapH3c.getRoadmapH3cParamValue3());

                // 根据key + year 查询 明后 年的值
                RoadmapH3c roadmapH3cByYearAndKey = roadmapH3cDao.getRoadmapH3cByYearAndKey(yearAdd1.toString(), roadmapH3c.getRoadmapH3cParamKey(), versionY, versionN);
                if (roadmapH3cByYearAndKey != null) {
                    roadmapH3c.setCurrentYearAdd1Value1(roadmapH3cByYearAndKey.getRoadmapH3cParamValue1());
                    roadmapH3c.setCurrentYearAdd1Value2(roadmapH3cByYearAndKey.getRoadmapH3cParamValue2());
                    roadmapH3c.setCurrentYearAdd1Value3(roadmapH3cByYearAndKey.getRoadmapH3cParamValue3());
                }
                RoadmapH3c roadmapH3cByYearAndKey2 = roadmapH3cDao.getRoadmapH3cByYearAndKey(yearAdd2.toString(), roadmapH3c.getRoadmapH3cParamKey(), versionY, versionN);
                if (roadmapH3cByYearAndKey2 != null) {
                    roadmapH3c.setCurrentYearAdd2Value1(roadmapH3cByYearAndKey2.getRoadmapH3cParamValue1());
                    roadmapH3c.setCurrentYearAdd2Value2(roadmapH3cByYearAndKey2.getRoadmapH3cParamValue2());
                    roadmapH3c.setCurrentYearAdd2Value3(roadmapH3cByYearAndKey2.getRoadmapH3cParamValue3());
                }
            }
            return ResultUtil.success(allRoadmapH3c);
        } catch (Exception e) {
            e.printStackTrace();
            return ResultUtil.error(500, e.getMessage(), e.getMessage(), null);
        }
    }

    @Override
    public Result exportExcelOfH3CRoadmaps(Integer year, Integer versionY, String versionN) {
        try {
            if (year == null || "".equals(year.toString())) {
                return ResultUtil.error(500, "缺少参数year", "Miss Param year", null);
            }
            if (versionY == null || "".equals(versionY.toString())) {
                return ResultUtil.error(500, "缺少参数versionY", "Miss Param versionY", null);
            }
            if (versionN == null || "".equals(versionN)) {
                return ResultUtil.error(500, "缺少参数versionN", "Miss Param versionN", null);
            }
            // 查询roadmap 所有大类
            List<RoadmapBigType> allRoadmapBigType = roadmapBigTypeDao.getAllRoadmapBigType(null);
            for (RoadmapBigType roadmapBigType : allRoadmapBigType) {
                List<RoadmapSmallType> allRoadmapSmallType = roadmapSmallTypeDao.getAllRoadmapSmallType(null, roadmapBigType.getRoadmapBigTypeId());
                for (RoadmapSmallType roadmapSmallType : allRoadmapSmallType) {
                    List<RoadmapParam> allRoadmapParam = roadmapParamDao.getAllRoadmapParam(null, roadmapBigType.getRoadmapBigTypeId(), roadmapSmallType.getRoadmapSmallTypeId());
                    roadmapSmallType.setRoadmapParamList(allRoadmapParam);
                }
                roadmapBigType.setRoadmapSmallTypeList(allRoadmapSmallType);
            }

            String excelName = "H3C roadmap能力表";
            // 创建工作簿对象
            Workbook workbook = new XSSFWorkbook();
            // 创建工作表对象
            Sheet sheet = workbook.createSheet(CommonUtils.handleSheetName(excelName));
            // 创建行和单元格对象
            Row row = sheet.createRow(0);

            CellStyle bigTitleContextCellStyle = workbook.createCellStyle();
            Font bigTitleFont = workbook.createFont();
            bigTitleFont.setBold(true);
            bigTitleFont.setFontHeightInPoints((short) 20);
            bigTitleContextCellStyle.setFont(bigTitleFont);
            bigTitleContextCellStyle.setAlignment(HorizontalAlignment.CENTER);
            bigTitleContextCellStyle.setVerticalAlignment(VerticalAlignment.CENTER);

            CellStyle bodyContextCellStyle = workbook.createCellStyle();
            DataFormat format = workbook.createDataFormat();
            bodyContextCellStyle.setDataFormat(format.getFormat("@"));
            bodyContextCellStyle.setBorderBottom(BorderStyle.THIN);
            bodyContextCellStyle.setBorderLeft(BorderStyle.THIN);
            bodyContextCellStyle.setBorderRight(BorderStyle.THIN);
            bodyContextCellStyle.setBorderTop(BorderStyle.THIN);
            bodyContextCellStyle.setAlignment(HorizontalAlignment.LEFT);
            bodyContextCellStyle.setVerticalAlignment(VerticalAlignment.CENTER);

            CellStyle titleContextCellStyle = workbook.createCellStyle();
            titleContextCellStyle.setBorderBottom(BorderStyle.MEDIUM);
            titleContextCellStyle.setBorderLeft(BorderStyle.MEDIUM);
            titleContextCellStyle.setBorderRight(BorderStyle.MEDIUM);
            titleContextCellStyle.setBorderTop(BorderStyle.MEDIUM);
            titleContextCellStyle.setAlignment(HorizontalAlignment.CENTER);
            titleContextCellStyle.setVerticalAlignment(VerticalAlignment.CENTER);
            // 设置背景色为红色
            titleContextCellStyle.setFillForegroundColor(IndexedColors.BLUE.getIndex());
            // 创建字体对象
            Font titleFont = workbook.createFont();
            // 设置字体颜色为蓝色
            titleFont.setColor(IndexedColors.WHITE.getIndex());
            titleFont.setBold(true);
            titleContextCellStyle.setFont(titleFont);
            // 设置填充类型为填充实体背景
            titleContextCellStyle.setFillPattern(FillPatternType.SOLID_FOREGROUND);

            // 第一行大标题
            Cell cell = row.createCell(0);
            cell.setCellValue("大类");
            sheet.setColumnWidth(0, 7000);
            cell.setCellStyle(titleContextCellStyle);

            cell = row.createCell(1);
            cell.setCellValue("小类");
            sheet.setColumnWidth(1, 7000);
            cell.setCellStyle(titleContextCellStyle);

            cell = row.createCell(2);
            cell.setCellValue("能力项");
            sheet.setColumnWidth(2, 14000);
            cell.setCellStyle(titleContextCellStyle);

            cell = row.createCell(3);
            cell.setCellValue("key值");
            sheet.setColumnWidth(3, 3000);
            cell.setCellStyle(titleContextCellStyle);

            cell = row.createCell(4);
            cell.setCellValue("说明");
            sheet.setColumnWidth(4, 14000);
            cell.setCellStyle(titleContextCellStyle);

            cell = row.createCell(5);
            cell.setCellValue("数据格式");
            sheet.setColumnWidth(5, 14000);
            cell.setCellStyle(titleContextCellStyle);

            cell = row.createCell(6);
            cell.setCellValue("H3C能力roadmap");
            cell.setCellStyle(titleContextCellStyle);


            // 第二行
            row = sheet.createRow(1);

            //补充第一行【不然边框渲染不完整】
            cell = row.createCell(0);
            cell.setCellValue("大类");
            sheet.setColumnWidth(0, 7000);
            cell.setCellStyle(titleContextCellStyle);

            cell = row.createCell(1);
            cell.setCellValue("小类");
            sheet.setColumnWidth(1, 7000);
            cell.setCellStyle(titleContextCellStyle);

            cell = row.createCell(2);
            cell.setCellValue("能力项");
            sheet.setColumnWidth(2, 14000);
            cell.setCellStyle(titleContextCellStyle);

            cell = row.createCell(3);
            cell.setCellValue("key值");
            sheet.setColumnWidth(3, 3000);
            cell.setCellStyle(titleContextCellStyle);

            cell = row.createCell(4);
            cell.setCellValue("说明");
            sheet.setColumnWidth(4, 14000);
            cell.setCellStyle(titleContextCellStyle);

            cell = row.createCell(5);
            cell.setCellValue("数据格式");
            sheet.setColumnWidth(5, 10000);
            cell.setCellStyle(titleContextCellStyle);

            // 开始第二行标头
            cell = row.createCell(6);
            cell.setCellValue("");
            sheet.setColumnWidth(6, 5000);
            cell.setCellStyle(titleContextCellStyle);
            cell = row.createCell(7);
            cell.setCellValue(year + "年");
            sheet.setColumnWidth(7, 5000);
            cell.setCellStyle(titleContextCellStyle);
            cell = row.createCell(8);
            cell.setCellValue((year + 1) + "年");
            sheet.setColumnWidth(8, 5000);
            cell.setCellStyle(titleContextCellStyle);
            cell = row.createCell(9);
            cell.setCellValue((year + 2) + "年");
            sheet.setColumnWidth(9, 5000);
            cell.setCellStyle(titleContextCellStyle);

            // 第一行合并单元格
            sheet.addMergedRegion(new CellRangeAddress(0, 1, 0, 0));
            sheet.addMergedRegion(new CellRangeAddress(0, 1, 1, 1));
            sheet.addMergedRegion(new CellRangeAddress(0, 1, 2, 2));
            sheet.addMergedRegion(new CellRangeAddress(0, 1, 3, 3));
            sheet.addMergedRegion(new CellRangeAddress(0, 1, 4, 4));
            sheet.addMergedRegion(new CellRangeAddress(0, 1, 5, 5));
            sheet.addMergedRegion(new CellRangeAddress(0, 0, 6, 9));

            // H3C数据从第三行开始、第0列到6列;
            // CM数据从第三行开始、第7列往后，每个 CM厂占 4列
            if (allRoadmapBigType.size() > 0) {
                int beginRowIndex = 2;
                int index1 = beginRowIndex;
                int index2 = beginRowIndex;
                for (int a = 0; a < allRoadmapBigType.size(); a++) {
                    if (allRoadmapBigType.get(a).getRoadmapSmallTypeList().size() > 0) {
                        for (int b = 0; b < allRoadmapBigType.get(a).getRoadmapSmallTypeList().size(); b++) {
                            List<RoadmapSmallType> roadmapSmallTypeList = allRoadmapBigType.get(a).getRoadmapSmallTypeList();
                            for (int c = 0; c < roadmapSmallTypeList.get(b).getRoadmapParamList().size(); c++) {
                                // 合并 能力项 一列
                                sheet.addMergedRegion(new CellRangeAddress(beginRowIndex, beginRowIndex + 2, 2, 2));
                                for (int d = 0; d < 3; d++) {
                                    row = sheet.createRow(beginRowIndex);
                                    // 大类
                                    cell = row.createCell(0);
                                    cell.setCellValue(allRoadmapBigType.get(a).getRoadmapBigTypeName());
                                    // 小类
                                    cell = row.createCell(1);
                                    cell.setCellValue(roadmapSmallTypeList.get(b).getRoadmapSmallTypeName());
                                    // 能力项
                                    cell = row.createCell(2);
                                    cell.setCellValue(roadmapSmallTypeList.get(b).getRoadmapParamList().get(c).getRoadmapParamName());
                                    // key值
                                    cell = row.createCell(3);
                                    cell.setCellValue(roadmapSmallTypeList.get(b).getRoadmapParamList().get(c).getRoadmapParamKey());
                                    // 说明
                                    cell = row.createCell(4);
                                    cell.setCellValue(roadmapSmallTypeList.get(b).getRoadmapParamList().get(c).getRoadmapParamNotes());
                                    // 数据格式
                                    cell = row.createCell(5);
                                    //                                    1：普通文本
//                                    2：下拉单选
//                                    3：下拉多选
//                                    4：整数
//                                    5：小数
//                                    6：百分比
                                    Integer roadmapParamType = roadmapSmallTypeList.get(b).getRoadmapParamList().get(c).getRoadmapParamType();
                                    String roadmapParamTypeStr = "";
                                    if (roadmapParamType == 1) {
                                        roadmapParamTypeStr = "普通文本";
                                    } else if (roadmapParamType == 2) {
                                        String roadmapParamOptions = roadmapSmallTypeList.get(b).getRoadmapParamList().get(c).getRoadmapParamOptions();
                                        roadmapParamTypeStr = "下拉单选(" + roadmapParamOptions + ")";
                                    } else if (roadmapParamType == 3) {
                                        String roadmapParamOptions = roadmapSmallTypeList.get(b).getRoadmapParamList().get(c).getRoadmapParamOptions();
                                        roadmapParamTypeStr = "下拉多选(" + roadmapParamOptions + ")";
                                    } else if (roadmapParamType == 4) {
                                        roadmapParamTypeStr = "整数";
                                    } else if (roadmapParamType == 5) {
                                        roadmapParamTypeStr = "小数";
                                    } else if (roadmapParamType == 6) {
                                        roadmapParamTypeStr = "百分比";
                                    }
                                    cell.setCellValue(roadmapParamTypeStr);

                                    // 查询具体的值
                                    //今年
                                    RoadmapH3c roadmapH3cByKey1 = roadmapH3cDao.getRoadmapH3cByKey(roadmapSmallTypeList.get(b).getRoadmapParamList().get(c).getRoadmapParamKey(), year, versionY, versionN);
                                    //明年
                                    RoadmapH3c roadmapH3cByKey2 = roadmapH3cDao.getRoadmapH3cByKey(roadmapSmallTypeList.get(b).getRoadmapParamList().get(c).getRoadmapParamKey(), year + 1, versionY, versionN);
                                    //后年
                                    RoadmapH3c roadmapH3cByKey3 = roadmapH3cDao.getRoadmapH3cByKey(roadmapSmallTypeList.get(b).getRoadmapParamList().get(c).getRoadmapParamKey(), year + 2, versionY, versionN);

                                    if ((beginRowIndex - 2) % 3 == 0) {
                                        cell = row.createCell(6);
                                        cell.setCellValue("量产能力");
                                        cell = row.createCell(7);
                                        cell.setCellValue(roadmapH3cByKey1 != null ? roadmapH3cByKey1.getRoadmapH3cParamValue1() : "");
                                        cell = row.createCell(8);
                                        cell.setCellValue(roadmapH3cByKey2 != null ? roadmapH3cByKey2.getRoadmapH3cParamValue1() : "");
                                        cell = row.createCell(9);
                                        cell.setCellValue(roadmapH3cByKey3 != null ? roadmapH3cByKey3.getRoadmapH3cParamValue1() : "");
                                    } else if ((beginRowIndex - 2) % 3 == 1) {
                                        cell = row.createCell(6);
                                        cell.setCellValue("小批量能力");
                                        cell = row.createCell(7);
                                        cell.setCellValue(roadmapH3cByKey1 != null ? roadmapH3cByKey1.getRoadmapH3cParamValue2() : "");
                                        cell = row.createCell(8);
                                        cell.setCellValue(roadmapH3cByKey2 != null ? roadmapH3cByKey2.getRoadmapH3cParamValue2() : "");
                                        cell = row.createCell(9);
                                        cell.setCellValue(roadmapH3cByKey3 != null ? roadmapH3cByKey3.getRoadmapH3cParamValue2() : "");
                                    } else {
                                        cell = row.createCell(6);
                                        cell.setCellValue("预研能力");
                                        cell = row.createCell(7);
                                        cell.setCellValue(roadmapH3cByKey1 != null ? roadmapH3cByKey1.getRoadmapH3cParamValue3() : "");
                                        cell = row.createCell(8);
                                        cell.setCellValue(roadmapH3cByKey2 != null ? roadmapH3cByKey2.getRoadmapH3cParamValue3() : "");
                                        cell = row.createCell(9);
                                        cell.setCellValue(roadmapH3cByKey3 != null ? roadmapH3cByKey3.getRoadmapH3cParamValue3() : "");
                                    }

                                    beginRowIndex++;
                                }
                            }
                            // 合并 小类 一列
                            if (index2 <= beginRowIndex - 1) {
                                sheet.addMergedRegion(new CellRangeAddress(index2, beginRowIndex - 1, 1, 1));
                            }
                            index2 = beginRowIndex;
                        }
                        // 合并 大类 一列
                        if (index1 <= beginRowIndex - 1) {
                            sheet.addMergedRegion(new CellRangeAddress(index1, beginRowIndex - 1, 0, 0));
                        }
                        index1 = beginRowIndex;
                    }
                }
            }

            String fileName = excelName + CommonUtils.getTimestamp() + ".xlsx";
            String pathPrefix = fileSaveUrl + "exportExcels\\";
            File folder = new File(pathPrefix);
            if (!folder.isDirectory()) {
                folder.mkdirs();
            }
            String filePath = pathPrefix + fileName;
            // 导出Excel文件
            FileOutputStream outputStream = new FileOutputStream(filePath);
            workbook.write(outputStream);
            workbook.close();
            outputStream.close();

            byte[] data = null;
            InputStream in = new FileInputStream(filePath);
            data = new byte[in.available()];
            in.read(data);
            in.close();
            java.util.Base64.Encoder encoder = java.util.Base64.getEncoder();
            String base64 = encoder.encodeToString(data);

            Map<String, Object> resMap = new HashMap<>();
            resMap.put("base64", base64);
            resMap.put("fileName", fileName);
            resMap.put("allRoadmapBigType", allRoadmapBigType);
            return ResultUtil.success(resMap);
        } catch (Exception e) {
            e.printStackTrace();
            return ResultUtil.error(500, e.getMessage(), e.getMessage(), null);
        }
    }

    @Override
    public Result getHistoryVersion() {
        try {
            return ResultUtil.success(roadmapH3cDao.getHistoryVersion());
        } catch (Exception e) {
            e.printStackTrace();
            return ResultUtil.error(500, e.getMessage(), e.getMessage(), null);
        }
    }

    @Override
    public Result getMaxHistoryVersionByYear(Integer versionY) {
        try {
            if (versionY == null || "".equals(versionY.toString())) {
                return ResultUtil.error(500, "缺少参数versionY", "Miss Param versionY", null);
            }
            return ResultUtil.success(roadmapH3cDao.getMaxHistoryVersionByYear(versionY));
        } catch (Exception e) {
            e.printStackTrace();
            return ResultUtil.error(500, e.getMessage(), e.getMessage(), null);
        }
    }

    @Override
    public Result copyNextVersionH3CRoadmaps(Integer currentVersionY, String currentVersionN, Integer nextVersionY, String nextVersionN) {
        try {
            if (currentVersionY == null || "".equals(currentVersionY.toString())) {
                return ResultUtil.error(500, "缺少参数currentVersionY", "Miss Param currentVersionY", null);
            }
            if (currentVersionN == null || "".equals(currentVersionN)) {
                return ResultUtil.error(500, "缺少参数currentVersionN", "Miss Param currentVersionN", null);
            }
            if (nextVersionY == null || "".equals(nextVersionY.toString())) {
                return ResultUtil.error(500, "缺少参数nextVersionY", "Miss Param nextVersionY", null);
            }
            if (nextVersionN == null || "".equals(nextVersionN)) {
                return ResultUtil.error(500, "缺少参数nextVersionN", "Miss Param nextVersionN", null);
            }
            // 查询原先的
            List<RoadmapH3c> list = roadmapH3cDao.getAllRoadmapH3c(null, currentVersionY, currentVersionN);
            Date d = new Date();
            String userId = UserHeaderHolder.getUserId();
            List<RoadmapH3c> newUpdateList = new ArrayList<>();
            List<RoadmapH3c> newAddList = new ArrayList<>();
            List<RoadmapH3c> oldList = new ArrayList<>();
            for (RoadmapH3c roadmapH3c : list) {

                // insert
                RoadmapH3c addRoadmapH3c = new RoadmapH3c();
                addRoadmapH3c.setVersionN(nextVersionN);
                addRoadmapH3c.setVersionY(nextVersionY);
                addRoadmapH3c.setCreateTime(d);
                addRoadmapH3c.setRoadmapH3cParamKey(roadmapH3c.getRoadmapH3cParamKey());
                addRoadmapH3c.setRoadmapH3cParamValue1(roadmapH3c.getRoadmapH3cParamValue1());
                addRoadmapH3c.setRoadmapH3cParamValue2(roadmapH3c.getRoadmapH3cParamValue2());
                addRoadmapH3c.setRoadmapH3cParamValue3(roadmapH3c.getRoadmapH3cParamValue3());
                addRoadmapH3c.setSort(roadmapH3c.getSort());
                addRoadmapH3c.setStatus(roadmapH3c.getStatus());
                addRoadmapH3c.setYear(roadmapH3c.getYear());

                newAddList.add(addRoadmapH3c);
            }
            if (newAddList.size() > 0) {
                roadmapH3cDao.batchAddProjectNode(newAddList);
                // 添加操作日志
                operateService.addOperate(new Operate(1, Integer.parseInt(userId), operateSmallType, 1, 1, new Date(), null, JSONObject.toJSONString(newAddList)));
            }

            //newAddList.addAll(newUpdateList);


            return ResultUtil.success(null);
        } catch (Exception e) {
            e.printStackTrace();
            return ResultUtil.error(500, e.getMessage(), e.getMessage(), null);
        }
    }

    @Transactional(transactionManager = "MysqlTransactionManager1")
    @Override
    public Result importRoadmapH3cExcel(MultipartFile file) {
        try {
            if (file == null) {
                return ResultUtil.error(500, "缺少参数file", "Miss Param file", null);
            }
            List<Map<String, Object>> list = new ArrayList<>();
            // 1.得到一个输入流对象
            //FileInputStream in = FileConverterUtils.convertTo(file);
            InputStream inputStream = file.getInputStream();
            File f = FileConverterUtils.getTempFileFromInputStream(inputStream);
            // 2.将输入流对象进行解析 得到workbook对象
            //Workbook workbook = new XSSFWorkbook(in);
            Workbook workbook = WorkbookFactory.create(f);
            // 3.workbook中有几个工作簿
            int sheetNum = workbook.getNumberOfSheets();
            System.out.println("一共有" + sheetNum + "个工作簿");
            // 3.1通过workbook 创建工作簿对象
            //Sheet sheet1 = workbook.getSheetAt(0);
            //Sheet sheet2 = workbook.getSheetAt(1);

            // 查询 roadmap最新版本
            Integer version_y = 0;
            String version_n = "";
            List<RoadmapH3c> historyVersion = roadmapH3cDao.getHistoryVersion();
            if (historyVersion.size() > 0) {
                version_y = historyVersion.get(historyVersion.size() - 1).getVersionY();
                version_n = historyVersion.get(historyVersion.size() - 1).getVersionN();
            }
            if (version_y == 0 || "".equals(version_n)) {
                return ResultUtil.error(500, "未能获取到最新版本", "Not Found Newest Version", null);
            }

            // 今年
            Calendar cal = Calendar.getInstance();
            Integer year = cal.get(Calendar.YEAR);
            //明年
            Integer yearAdd1 = year + 1;
            //后年
            Integer yearAdd2 = year + 2;

            for (int a = 0; a < 1; a++) {
                Sheet sheet = workbook.getSheetAt(a);
                int allRows = sheet.getLastRowNum() + 1;
                System.out.println("sheet" + (a + 1) + "一共有：" + allRows + "行");
                String sheetName = sheet.getSheetName();
                System.out.println("当前sheetName：" + sheetName);

                Map<String, Object> map = new HashMap<>();
                //标题行 第1行开始
                Row row = sheet.getRow(0);
                String t1 = row.getCell(0) != null ? row.getCell(0).toString() : "";
                String t2 = row.getCell(1) != null ? row.getCell(1).toString() : "";
                String t3 = row.getCell(2) != null ? row.getCell(2).toString() : "";
                String t4 = row.getCell(3) != null ? row.getCell(3).toString() : "";
                String t5 = row.getCell(4) != null ? row.getCell(4).toString() : "";
                String t6 = row.getCell(5) != null ? row.getCell(5).toString() : "";
                String t7 = row.getCell(6) != null ? row.getCell(6).toString() : "";
                if (t1.contains("大类") &&
                        t2.contains("小类") &&
                        t3.contains("能力项") &&
                        t4.contains("key值") &&
                        t5.contains("说明") &&
                        t6.contains("数据格式") &&
                        t7.contains("H3C能力roadmap")
                ) {
                    // 表头符合的，循环获取每行数据
                    //List<Map<String,Object>> list2 = new ArrayList<>();
                    for (int b = 2; b < allRows; b++) {
                        Row rowV = sheet.getRow(b);
                        String v4 = rowV.getCell(3) != null ? rowV.getCell(3).toString() : "";
                        String v8 = rowV.getCell(7) != null ? rowV.getCell(7).toString() : "";
                        String v9 = rowV.getCell(8) != null ? rowV.getCell(8).toString() : "";
                        String v10 = rowV.getCell(9) != null ? rowV.getCell(9).toString() : "";
                        // 只要管 第4列、 第8列、第9列、第10列的值即可，为 当年值、明年值、后年值

                        Map<String, Object> map2 = new HashMap<>();
                        // 从第 3 行开始，每行取值
                        if ((b - 2) % 3 == 0) {
                            map2.put("roadmapH3cParamKey", v4);
                            Map<String, Object> map3 = new HashMap<>();
                            map3.put("roadmapH3cValueYear", v8);
                            map3.put("roadmapH3cValueYearAdd1", v9);
                            map3.put("roadmapH3cValueYearAdd2", v10);
                            map2.put("roadmapH3cParamValue1", map3);
                        }
                        if ((b - 2) % 3 == 1) {
                            map2.put("roadmapH3cParamKey", v4);
                            Map<String, Object> map3 = new HashMap<>();
                            map3.put("roadmapH3cValueYear", v8);
                            map3.put("roadmapH3cValueYearAdd1", v9);
                            map3.put("roadmapH3cValueYearAdd2", v10);
                            map2.put("roadmapH3cParamValue2", map3);
                        }
                        if ((b - 2) % 3 == 2) {
                            map2.put("roadmapH3cParamKey", v4);
                            Map<String, Object> map3 = new HashMap<>();
                            map3.put("roadmapH3cValueYear", v8);
                            map3.put("roadmapH3cValueYearAdd1", v9);
                            map3.put("roadmapH3cValueYearAdd2", v10);
                            map2.put("roadmapH3cParamValue3", map3);
                        }
                        list.add(map2);
                    }
                } else {
                    return ResultUtil.error(500, "模板错误", "Error Template", null);
                }
            }

            // 重新构造 list
            List<Map<String, Object>> finalList = new ArrayList<>();
            List<String> keyList = new ArrayList<>();
            for (Map<String, Object> stringObjectMap : list) {
                String roadmapH3cParamKey = (String) stringObjectMap.get("roadmapH3cParamKey");
                if (!keyList.contains(roadmapH3cParamKey)) {
                    keyList.add(roadmapH3cParamKey);
                }
            }
            for (String key : keyList) {
                String roadmapH3cParamValue1_year = "";// 量产能力值
                String roadmapH3cParamValue2_year = "";// 小批量能力
                String roadmapH3cParamValue3_year = "";// 预研能力
                String roadmapH3cParamValue1_yearAdd1 = "";// 量产能力值
                String roadmapH3cParamValue2_yearAdd1 = "";// 小批量能力
                String roadmapH3cParamValue3_yearAdd1 = "";// 预研能力
                String roadmapH3cParamValue1_yearAdd2 = "";// 量产能力值
                String roadmapH3cParamValue2_yearAdd2 = "";// 小批量能力
                String roadmapH3cParamValue3_yearAdd2 = "";// 预研能力
                for (Map<String, Object> stringObjectMap : list) {
                    String roadmapH3cParamKey = (String) stringObjectMap.get("roadmapH3cParamKey");
                    if (key.equals(roadmapH3cParamKey) && stringObjectMap.get("roadmapH3cParamValue1") != null) {
                        Map<String, Object> roadmapH3cParamValueMap = (Map<String, Object>) stringObjectMap.get("roadmapH3cParamValue1");
                        String roadmapH3cValueYear = (String) roadmapH3cParamValueMap.get("roadmapH3cValueYear");
                        String roadmapH3cValueYearAdd1 = (String) roadmapH3cParamValueMap.get("roadmapH3cValueYearAdd1");
                        String roadmapH3cValueYearAdd2 = (String) roadmapH3cParamValueMap.get("roadmapH3cValueYearAdd2");
                        roadmapH3cParamValue1_year = roadmapH3cValueYear;
                        roadmapH3cParamValue1_yearAdd1 = roadmapH3cValueYearAdd1;
                        roadmapH3cParamValue1_yearAdd2 = roadmapH3cValueYearAdd2;
                        break;
                    }
                }
                for (Map<String, Object> stringObjectMap : list) {
                    String roadmapH3cParamKey = (String) stringObjectMap.get("roadmapH3cParamKey");
                    if (key.equals(roadmapH3cParamKey) && stringObjectMap.get("roadmapH3cParamValue2") != null) {
                        Map<String, Object> roadmapH3cParamValueMap = (Map<String, Object>) stringObjectMap.get("roadmapH3cParamValue2");
                        String roadmapH3cValueYear = (String) roadmapH3cParamValueMap.get("roadmapH3cValueYear");
                        String roadmapH3cValueYearAdd1 = (String) roadmapH3cParamValueMap.get("roadmapH3cValueYearAdd1");
                        String roadmapH3cValueYearAdd2 = (String) roadmapH3cParamValueMap.get("roadmapH3cValueYearAdd2");
                        roadmapH3cParamValue2_year = roadmapH3cValueYear;
                        roadmapH3cParamValue2_yearAdd1 = roadmapH3cValueYearAdd1;
                        roadmapH3cParamValue2_yearAdd2 = roadmapH3cValueYearAdd2;
                        break;
                    }
                }
                for (Map<String, Object> stringObjectMap : list) {
                    String roadmapH3cParamKey = (String) stringObjectMap.get("roadmapH3cParamKey");
                    if (key.equals(roadmapH3cParamKey) && stringObjectMap.get("roadmapH3cParamValue3") != null) {
                        Map<String, Object> roadmapH3cParamValueMap = (Map<String, Object>) stringObjectMap.get("roadmapH3cParamValue3");
                        String roadmapH3cValueYear = (String) roadmapH3cParamValueMap.get("roadmapH3cValueYear");
                        String roadmapH3cValueYearAdd1 = (String) roadmapH3cParamValueMap.get("roadmapH3cValueYearAdd1");
                        String roadmapH3cValueYearAdd2 = (String) roadmapH3cParamValueMap.get("roadmapH3cValueYearAdd2");
                        roadmapH3cParamValue3_year = roadmapH3cValueYear;
                        roadmapH3cParamValue3_yearAdd1 = roadmapH3cValueYearAdd1;
                        roadmapH3cParamValue3_yearAdd2 = roadmapH3cValueYearAdd2;
                        break;
                    }
                }

                JSONObject jo = new JSONObject();
                jo.put("roadmapH3cParamKey", key);
                JSONObject jo1 = new JSONObject();
                jo1.put("roadmapH3cParamValue1", roadmapH3cParamValue1_year != null ? CommonUtils.removeZeros(roadmapH3cParamValue1_year) : "");
                jo1.put("roadmapH3cParamValue2", roadmapH3cParamValue2_year != null ? CommonUtils.removeZeros(roadmapH3cParamValue2_year) : "");
                jo1.put("roadmapH3cParamValue3", roadmapH3cParamValue3_year != null ? CommonUtils.removeZeros(roadmapH3cParamValue3_year) : "");
                jo1.put("year", year);
                jo.put("roadmapH3cParamValue1", jo1);

                JSONObject jo2 = new JSONObject();
                jo2.put("roadmapH3cParamValue1", roadmapH3cParamValue1_yearAdd1 != null ? CommonUtils.removeZeros(roadmapH3cParamValue1_yearAdd1) : "");
                jo2.put("roadmapH3cParamValue2", roadmapH3cParamValue2_yearAdd1 != null ? CommonUtils.removeZeros(roadmapH3cParamValue2_yearAdd1) : "");
                jo2.put("roadmapH3cParamValue3", roadmapH3cParamValue3_yearAdd1 != null ? CommonUtils.removeZeros(roadmapH3cParamValue3_yearAdd1) : "");
                jo2.put("year", yearAdd1);
                jo.put("roadmapH3cParamValue2", jo2);

                JSONObject jo3 = new JSONObject();
                jo3.put("roadmapH3cParamValue1", roadmapH3cParamValue1_yearAdd2 != null ? CommonUtils.removeZeros(roadmapH3cParamValue1_yearAdd2) : "");
                jo3.put("roadmapH3cParamValue2", roadmapH3cParamValue2_yearAdd2 != null ? CommonUtils.removeZeros(roadmapH3cParamValue2_yearAdd2) : "");
                jo3.put("roadmapH3cParamValue3", roadmapH3cParamValue3_yearAdd2 != null ? CommonUtils.removeZeros(roadmapH3cParamValue3_yearAdd2) : "");
                jo3.put("year", yearAdd2);
                jo.put("roadmapH3cParamValue3", jo3);
                finalList.add(jo);
            }

            Date d = new Date();
            String userId = UserHeaderHolder.getUserId();

            List<RoadmapH3c> oldList = new ArrayList<>();
            List<RoadmapH3c> newList = new ArrayList<>();

            for (Map<String, Object> stringObjectMap : finalList) {
                String roadmapH3cParamKey = (String) stringObjectMap.get("roadmapH3cParamKey");
                JSONObject jsonObject1 = (JSONObject) stringObjectMap.get("roadmapH3cParamValue1");
                String roadmapH3cParamValue1_1 = jsonObject1.getString("roadmapH3cParamValue1");
                String roadmapH3cParamValue1_2 = jsonObject1.getString("roadmapH3cParamValue2");
                String roadmapH3cParamValue1_3 = jsonObject1.getString("roadmapH3cParamValue3");
                JSONObject jsonObject2 = (JSONObject) stringObjectMap.get("roadmapH3cParamValue2");
                String roadmapH3cParamValue2_1 = jsonObject2.getString("roadmapH3cParamValue1");
                String roadmapH3cParamValue2_2 = jsonObject2.getString("roadmapH3cParamValue2");
                String roadmapH3cParamValue2_3 = jsonObject2.getString("roadmapH3cParamValue3");
                JSONObject jsonObject3 = (JSONObject) stringObjectMap.get("roadmapH3cParamValue3");
                String roadmapH3cParamValue3_1 = jsonObject3.getString("roadmapH3cParamValue1");
                String roadmapH3cParamValue3_2 = jsonObject3.getString("roadmapH3cParamValue2");
                String roadmapH3cParamValue3_3 = jsonObject3.getString("roadmapH3cParamValue3");

                RoadmapH3c roadmapH3cByKey1 = roadmapH3cDao.getRoadmapH3cByKey(roadmapH3cParamKey, year, version_y, version_n);
                if (roadmapH3cByKey1 == null) {
                    // insert
                    RoadmapH3c addRoadmapH3c = new RoadmapH3c();
                    addRoadmapH3c.setRoadmapH3cParamKey(roadmapH3cParamKey);
                    addRoadmapH3c.setRoadmapH3cParamValue1(roadmapH3cParamValue1_1);
                    addRoadmapH3c.setRoadmapH3cParamValue2(roadmapH3cParamValue1_2);
                    addRoadmapH3c.setRoadmapH3cParamValue3(roadmapH3cParamValue1_3);
                    addRoadmapH3c.setCreateTime(d);
                    addRoadmapH3c.setSort(100);
                    addRoadmapH3c.setStatus(1);
                    addRoadmapH3c.setYear(year);
                    addRoadmapH3c.setVersionY(version_y);
                    addRoadmapH3c.setVersionN(version_n);
                    roadmapH3cDao.addRoadmapH3c(addRoadmapH3c);
                    newList.add(addRoadmapH3c);
                } else {
                    // update
                    Integer roadmapH3cParamId = roadmapH3cByKey1.getRoadmapH3cParamId();
                    String roadmapH3cParamValue1 = roadmapH3cByKey1.getRoadmapH3cParamValue1() != null ? roadmapH3cByKey1.getRoadmapH3cParamValue1() : "";
                    String roadmapH3cParamValue2 = roadmapH3cByKey1.getRoadmapH3cParamValue2() != null ? roadmapH3cByKey1.getRoadmapH3cParamValue2() : "";
                    String roadmapH3cParamValue3 = roadmapH3cByKey1.getRoadmapH3cParamValue3() != null ? roadmapH3cByKey1.getRoadmapH3cParamValue3() : "";
                    if (!roadmapH3cParamValue1.equals(roadmapH3cParamValue1_1) || !roadmapH3cParamValue2.equals(roadmapH3cParamValue1_2) || !roadmapH3cParamValue3.equals(roadmapH3cParamValue1_3)) {
                        oldList.add(roadmapH3cByKey1);
                        RoadmapH3c updateRoadmapH3c = new RoadmapH3c();
                        updateRoadmapH3c.setRoadmapH3cParamKey(roadmapH3cParamKey);
                        updateRoadmapH3c.setRoadmapH3cParamValue1(roadmapH3cParamValue1_1);
                        updateRoadmapH3c.setRoadmapH3cParamValue2(roadmapH3cParamValue1_2);
                        updateRoadmapH3c.setRoadmapH3cParamValue3(roadmapH3cParamValue1_3);
                        updateRoadmapH3c.setUpdateTime(d);
                        updateRoadmapH3c.setSort(100);
                        updateRoadmapH3c.setStatus(1);
                        updateRoadmapH3c.setYear(year);
                        updateRoadmapH3c.setVersionY(version_y);
                        updateRoadmapH3c.setVersionN(version_n);
                        updateRoadmapH3c.setRoadmapH3cParamId(roadmapH3cParamId);
                        roadmapH3cDao.updateRoadmapH3c(updateRoadmapH3c);
                        newList.add(updateRoadmapH3c);
                    }
                }

                RoadmapH3c roadmapH3cByKey2 = roadmapH3cDao.getRoadmapH3cByKey(roadmapH3cParamKey, yearAdd1, version_y, version_n);
                if (roadmapH3cByKey2 == null) {
                    // insert
                    RoadmapH3c addRoadmapH3c = new RoadmapH3c();
                    addRoadmapH3c.setRoadmapH3cParamKey(roadmapH3cParamKey);
                    addRoadmapH3c.setRoadmapH3cParamValue1(roadmapH3cParamValue2_1);
                    addRoadmapH3c.setRoadmapH3cParamValue2(roadmapH3cParamValue2_2);
                    addRoadmapH3c.setRoadmapH3cParamValue3(roadmapH3cParamValue2_3);
                    addRoadmapH3c.setCreateTime(d);
                    addRoadmapH3c.setSort(100);
                    addRoadmapH3c.setStatus(1);
                    addRoadmapH3c.setYear(yearAdd1);
                    addRoadmapH3c.setVersionY(version_y);
                    addRoadmapH3c.setVersionN(version_n);
                    roadmapH3cDao.addRoadmapH3c(addRoadmapH3c);
                    newList.add(addRoadmapH3c);
                } else {
                    // update
                    Integer roadmapH3cParamId = roadmapH3cByKey2.getRoadmapH3cParamId();
                    String roadmapH3cParamValue1 = roadmapH3cByKey2.getRoadmapH3cParamValue1() != null ? roadmapH3cByKey2.getRoadmapH3cParamValue1() : "";
                    ;
                    String roadmapH3cParamValue2 = roadmapH3cByKey2.getRoadmapH3cParamValue2() != null ? roadmapH3cByKey2.getRoadmapH3cParamValue2() : "";
                    ;
                    String roadmapH3cParamValue3 = roadmapH3cByKey2.getRoadmapH3cParamValue3() != null ? roadmapH3cByKey2.getRoadmapH3cParamValue3() : "";
                    ;
                    if (!roadmapH3cParamValue1.equals(roadmapH3cParamValue2_1) || !roadmapH3cParamValue2.equals(roadmapH3cParamValue2_2) || !roadmapH3cParamValue3.equals(roadmapH3cParamValue2_3)) {
                        oldList.add(roadmapH3cByKey2);
                        RoadmapH3c updateRoadmapH3c = new RoadmapH3c();
                        updateRoadmapH3c.setRoadmapH3cParamKey(roadmapH3cParamKey);
                        updateRoadmapH3c.setRoadmapH3cParamValue1(roadmapH3cParamValue2_1);
                        updateRoadmapH3c.setRoadmapH3cParamValue2(roadmapH3cParamValue2_2);
                        updateRoadmapH3c.setRoadmapH3cParamValue3(roadmapH3cParamValue2_3);
                        updateRoadmapH3c.setUpdateTime(d);
                        updateRoadmapH3c.setSort(100);
                        updateRoadmapH3c.setStatus(1);
                        updateRoadmapH3c.setYear(yearAdd1);
                        updateRoadmapH3c.setVersionY(version_y);
                        updateRoadmapH3c.setVersionN(version_n);
                        updateRoadmapH3c.setRoadmapH3cParamId(roadmapH3cParamId);
                        roadmapH3cDao.updateRoadmapH3c(updateRoadmapH3c);
                        newList.add(updateRoadmapH3c);
                    }
                }

                RoadmapH3c roadmapH3cByKey3 = roadmapH3cDao.getRoadmapH3cByKey(roadmapH3cParamKey, yearAdd2, version_y, version_n);
                if (roadmapH3cByKey3 == null) {
                    // insert
                    RoadmapH3c addRoadmapH3c = new RoadmapH3c();
                    addRoadmapH3c.setRoadmapH3cParamKey(roadmapH3cParamKey);
                    addRoadmapH3c.setRoadmapH3cParamValue1(roadmapH3cParamValue3_1);
                    addRoadmapH3c.setRoadmapH3cParamValue2(roadmapH3cParamValue3_2);
                    addRoadmapH3c.setRoadmapH3cParamValue3(roadmapH3cParamValue3_3);
                    addRoadmapH3c.setCreateTime(d);
                    addRoadmapH3c.setSort(100);
                    addRoadmapH3c.setStatus(1);
                    addRoadmapH3c.setYear(yearAdd2);
                    addRoadmapH3c.setVersionY(version_y);
                    addRoadmapH3c.setVersionN(version_n);
                    roadmapH3cDao.addRoadmapH3c(addRoadmapH3c);
                    newList.add(addRoadmapH3c);
                } else {
                    // update
                    Integer roadmapH3cParamId = roadmapH3cByKey3.getRoadmapH3cParamId();
                    String roadmapH3cParamValue1 = roadmapH3cByKey3.getRoadmapH3cParamValue1() != null ? roadmapH3cByKey3.getRoadmapH3cParamValue1() : "";
                    ;
                    String roadmapH3cParamValue2 = roadmapH3cByKey3.getRoadmapH3cParamValue2() != null ? roadmapH3cByKey3.getRoadmapH3cParamValue2() : "";
                    ;
                    String roadmapH3cParamValue3 = roadmapH3cByKey3.getRoadmapH3cParamValue3() != null ? roadmapH3cByKey3.getRoadmapH3cParamValue3() : "";
                    ;
                    if (!roadmapH3cParamValue1.equals(roadmapH3cParamValue3_1) || !roadmapH3cParamValue2.equals(roadmapH3cParamValue3_2) || !roadmapH3cParamValue3.equals(roadmapH3cParamValue3_3)) {
                        oldList.add(roadmapH3cByKey3);
                        RoadmapH3c updateRoadmapH3c = new RoadmapH3c();
                        updateRoadmapH3c.setRoadmapH3cParamKey(roadmapH3cParamKey);
                        updateRoadmapH3c.setRoadmapH3cParamValue1(roadmapH3cParamValue3_1);
                        updateRoadmapH3c.setRoadmapH3cParamValue2(roadmapH3cParamValue3_2);
                        updateRoadmapH3c.setRoadmapH3cParamValue3(roadmapH3cParamValue3_3);
                        updateRoadmapH3c.setUpdateTime(d);
                        updateRoadmapH3c.setSort(100);
                        updateRoadmapH3c.setStatus(1);
                        updateRoadmapH3c.setYear(yearAdd2);
                        updateRoadmapH3c.setVersionY(version_y);
                        updateRoadmapH3c.setVersionN(version_n);
                        updateRoadmapH3c.setRoadmapH3cParamId(roadmapH3cParamId);
                        roadmapH3cDao.updateRoadmapH3c(updateRoadmapH3c);
                        newList.add(updateRoadmapH3c);
                    }
                }
            }

            if (newList.size() > 0) {
                // 操作日志
                operateService.addOperate(new Operate(1, Integer.parseInt(userId), operateSmallType, 3, 1, d, JSONObject.toJSONString(oldList), JSONObject.toJSONString(newList)));
            }
            Map<String, Object> m = new HashMap<>();
            m.put("finalList", finalList);
            m.put("newList", newList);
            return ResultUtil.success(m);
        } catch (Exception e) {
            TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
            e.printStackTrace();
            return ResultUtil.error(500, e.getMessage(), e.getMessage(), null);
        }
    }
}
